import 'package:clean_app/asset/color.dart';
import 'package:clean_app/pages/collect_tab/collect_tab.dart';
import 'package:clean_app/pages/me/me.dart';
import 'package:clean_app/pages/vision/vision.dart';
import 'package:clean_app/provider/login_provider.dart';
import 'package:clean_app/provider/task_provider.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  int currentIndex = 0;

  initUserData() async {
    var _p = Provider.of<UserProvider>(context, listen: false);
    _p.getLogined();
  }

  initNetwork() {
    Dio().request("https://www.baidu.com");
  }

  initPresetTags() {
    var _p = Provider.of<PresetTagProvider>(context, listen: false);
    _p.getData();
  }

  @override
  void initState() {
    initUserData();
    initNetwork();
    initPresetTags();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    bool isLogin = isLogined(context);
    return Scaffold(
      body: IndexedStack(
        index: currentIndex,
        children: [
          CollectTab(),
          VisionTab(),
          Me(),
        ],
      ),
      bottomNavigationBar: NavigationBar(
        selectedIndex: currentIndex,
        backgroundColor: os_white,
        indicatorColor: os_color_opa,
        onDestinationSelected: (val) {
          setState(() {
            currentIndex = val;
          });
        },
        destinations: const [
          NavigationDestination(
            icon: Icon(Icons.edit_outlined),
            selectedIcon: Icon(Icons.edit),
            label: "数据录入",
          ),
          NavigationDestination(
            icon: Icon(Icons.camera_alt_outlined),
            selectedIcon: Icon(Icons.camera_alt),
            label: "问问",
          ),
          NavigationDestination(
            icon: Icon(Icons.person_outline),
            selectedIcon: Icon(Icons.person),
            label: "我",
          ),
        ],
      ),
    );
  }
}
